package com.wgts.wgts.mvp.presenter.imp;

import com.wgts.wgts.mvp.model.IMoreMoreGoodInfoFragmentModel;
import com.wgts.wgts.mvp.presenter.IMoreMoreGoodInfoActivityPresenter;
import com.wgts.wgts.mvp.presenter.IMoreMoreGoodInfoFragmentPresenter;
import com.wgts.wgts.mvp.view.IMoreMoreGoodInfoFragmentView;
import com.wgts.wgts.tools.CountDownTime;
import com.wgts.wgts.tools.CountDownTimerListener;
import com.wgts.wgts.tools.Tools;

public class MoreMoreGoodInfoFragmentPresenter implements IMoreMoreGoodInfoFragmentPresenter {

    private IMoreMoreGoodInfoFragmentModel model;

    private IMoreMoreGoodInfoFragmentView view;

    private CountDownTime countDownTime;

    private long countTime;

    private CountDownTimerListener countDownTimerListener;

    public MoreMoreGoodInfoFragmentPresenter(IMoreMoreGoodInfoFragmentModel model, IMoreMoreGoodInfoFragmentView view , CountDownTime countDownTime) {
        this.model = model;
        this.view = view;
        this.countDownTime = countDownTime;
    }

    @Override
    public void startTimeCount(long time) {
        countTime = time;
        if(countDownTimerListener == null){
            countDownTimerListener = new CountDownTimerListener() {
                @Override
                public void countDownTimerListener() {
                    if(countTime > 0){
                        view.timeAction(Tools.change(countTime));
                        countTime--;
                    }else{
                        removeTimeCount();
                        view.timeOverRefresh();
                    }
                }
            };
            countDownTime.addCountDownTimerListener(countDownTimerListener);
        }
    }

    @Override
    public void removeTimeCount() {
        if(countDownTimerListener != null){
            countDownTime.removeCountDownTimerListener(countDownTimerListener);
            countDownTimerListener = null;
        }
    }
}
